/**
 * 
 */
package com.oron3.bouncer.objects.shapes;

/**
 * @author Ofek
 *
 */
public class ShapeUtils {

	/**
	 * 
	 * @param point - the point to which closest refers
	 * @param points - the candidates to be closest point
	 * @return the closest point out of points to point.
	 */
	public static Point closestPoint(final Point point, final Point... points) {
		if (points.length==0) throw new IllegalArgumentException();
		Point min = points[0];
		float minLength = point.sub(min).length();
		for ( int i = 0 ; i < points.length ; i++) {
			final Point p = points[i];
			final Point distanceVector = point.sub(p);
			final float length = distanceVector.length();
			if ( minLength>length ) {
				min = p;
				minLength = length; 
			}
		}
		return min;
	}

}
